# @Time    : 2018/6/6 11:30
# @Author  : Jame
from interface import common
from db import models



def consumer_register_interface(name,password):
    password=common.md5(password)
    obj=models.BasePeople.select(name)
    if not obj:
        consumer_obj=models.Consumer()
        consumer_obj.register(name, password)
        return True, '注册成功!'

    else:
        return False, '用户已经存在，请勿重复注册...'



def consumer_login_interface(name,password):
    password = common.md5(password) #因为md5解密困难，所以直接正解相等来判断！
    obj=models.BasePeople.select(name)
    if obj:
        if password==obj.password:
            capacity=obj.capacity
            balance=obj.balance
            home=obj.home
            return obj,'登陆成功'
        else:
            return False,'%s 密码错误，请重试...'%name

    else:
        return False,'%s 用户不存在，请重试...'%name


